package com.ushine.web.communication.httpurl;

import com.ushine.web.communication.httpurl.model.UserHttpQuery;
import com.ushine.web.communication.httpurl.model.UserHttpVO;
import com.ushine.web.component.http.HttpResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jetbrains.annotations.NotNull;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * @Author: yls
 * @Date 2022/5/7 14:13
 * @Description: httpUrl通信测试
 * @Version 1.0
 **/
@RestController
@Api(tags = "通信模块-httpUrl通信测试")
@RequestMapping("httpUrl")
public class HttUrlController {

    @ApiOperation(value = "测试GET请求")
    @GetMapping("testGet")
    public HttpResponseVO<UserHttpVO> testGet() {
        ArrayList<UserHttpVO> result = getTestResult();
        return new HttpResponseVO<UserHttpVO>().ok("服务端处理完成", result);
    }

    @ApiOperation(value = "测试PostT请求")
    @PostMapping("testPost")
    public HttpResponseVO<UserHttpVO> testPost(@RequestBody UserHttpQuery userHttpQuery) {
        ArrayList<UserHttpVO> result = getTestResult();
        return new HttpResponseVO<UserHttpVO>().ok("服务端处理完成", result);
    }

    @NotNull
    private ArrayList<UserHttpVO> getTestResult() {
        int dataSize = 10;
        ArrayList<UserHttpVO> result = new ArrayList<>();
        for (int i = 0; i < dataSize; i++) {
            UserHttpVO userHttpVO = new UserHttpVO();
            userHttpVO.setStatus(1);
            userHttpVO.setId(123456798L);
            userHttpVO.setTrueName("测试" + i);
            userHttpVO.setUsername("test" + i);
            result.add(userHttpVO);
        }
        return result;
    }
}
